<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        body {
            padding: 50px
        }

        button {
            width: 260px;
            height: 80px;
            background-color: #fff
        }
    </style>
</head>

<body>
<!--<button onclick="initMeiQia()">-->
<!--initMeiQia-->
<!--</button>-->
<!--<button onclick="meiQia_show()">-->
<!--meiQia_show-->
<!--</button>-->
<!--<button onclick="setTitleColor()">-->
<!--setTitleColor-->
<!--</button>-->
<!--<button onclick="setNavRightButton()">-->
<!--setNavRightButton-->
<!--</button>-->
<!--<button onclick="getUnreadMessageCount()">-->
<!--getUnreadMessageCount-->
<!--</button>-->
<!--<button onclick="setPreSendTextMessage()">-->
<!--setPreSendTextMessage-->
<!--</button>-->
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    var mq;
    function initMeiQia() {
        //创建美洽
        mq = api.require('meiQia');
        //配置初始化美洽需要的appkey
        var param = {
            appkey: "e2c5d30914366f50937a34e805cf29be"                                  // 这里需要填写自己在美洽申请的appkey
        };
        //初始化美洽
        mq.initMeiQia(param, function (ret, err) {
            if (ret) {
                //初始化成功
                // alert(JSON.stringify(ret));
                meiQia_show()
            } else {
                //初始化失败
                alert(JSON.stringify(err));
            }
        })
    };
    function meiQia_show() {
        mq.show();
    }

    function setTitleColor() {
        var mq = api.require('meiQia');
        //设置title以及按钮颜色
        var titleColor = {
            color: "#0000ff"
        };
        mq.setTitleColor(titleColor);
    }

    function setNavRightButton() {
        console.log(123);
        var buttonInfo = {
            title: "test",
            image: "http://www.apicloud.com/image/jpeg/54/1f/541f675422b1d4469711b78680d81c6a.30x30.jpg"
        };
        mq = api.require('meiQia');
        mq.setNavRightButton(buttonInfo, buttonTapCallback);

        function buttonTapCallback() {
            alert("button tapped")
        }

    }

    function getUnreadMessageCount() {
        mq = api.require('meiQia');
        mq.getUnreadMessageCount(unreadMessageCountCallback);

        function unreadMessageCountCallback(result) {
            alert("总共有" + result["count"] + "条未读消息");
        }

    }

    function setPreSendTextMessage() {
        var message = {
            message: "This is the presend message, you can put your product here to indicate to agent that the client is browsing it",
        };
        mq = api.require('meiQia');
        mq.setPreSendTextMessage(message);
    }

    apiready = function () {
        initMeiQia()
    }
</script>

</html>
